home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / Tools / Developers / PEDELF32.ZIP / pedelf32 / SECTION.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-09-30  |  7.9 KB  |  227 lines

  1. unit Section;
  2.  
  3. interface
  4.                  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, Mask;
  8.  
  9. type
  10.   TFrmSection = class(TForm)
  11.     LstSection: TListBox;
  12.     BtnOK: TBitBtn;
  13.     CmbSection: TComboBox;
  14.     BtnSetHeight: TButton;
  15.     EdtSectHeight: TEdit;
  16.     procedure FormShow(Sender: TObject);
  17.     procedure BtnOKClick(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure CmbSectionChange(Sender: TObject);
  20.     procedure BtnSetHeightClick(Sender: TObject);
  21.     function GetError(Const JobIn : Integer) : String;
  22.  
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.    FrmSection: TFrmSection;
  31.    Sections : Array[0..20] of integer;  {Used to store the loaded section codes}
  32.    SecIndex : Integer;    {Temporary Iterator}
  33.  
  34. implementation
  35.  
  36. Uses
  37.    Main, CRDelphi;
  38.  
  39. {$R *.DFM}
  40.  
  41. function TFrmSection.GetError(Const JobIn : Integer) : String;
  42. {This is my print engine error message capture function. It accepts
  43.  the job number as it parameter and then gets the error code and
  44.  message text and then passes this back out as a formatted string}
  45. var
  46.   Code : Integer;
  47.   StrHandle : hWnd;
  48.   Buffer : PChar;
  49.   Length : SmallInt;
  50.   Ret : Bool;
  51.  
  52. begin
  53.    Code := PEGetErrorCode(JobIn); {Get the Error code from the Crpe}
  54.    Ret := PEGetErrorText(JobIn, StrHandle, Length);  {Get the error message handle}
  55.  
  56.    Buffer := StrAlloc(Length);
  57.    {get the text from the text handle}
  58.    Ret := PEGetHandleString(StrHandle, Buffer, Length);
  59.  
  60.    GetError := IntToStr(Code) + ' - ' + StrPas(Buffer); {output the string}
  61.    StrDispose(Buffer);
  62. end;
  63.  
  64. procedure TFrmSection.FormShow(Sender: TObject);
  65. var
  66.    Temp, Iterator, NumGroups : SmallInt;
  67.    Ret : Bool;
  68.  
  69. begin
  70.    if SenderIsGet = True then   {menu option get section minimum was chosen}
  71.       {populate the sections listbox}
  72.       begin
  73.          LstSection.Visible := True;
  74.  
  75.          {Get the minimum section height for the page header}
  76.          If PEGetSectionHeight(JobNumber, PE_HEADERSECTION, Temp) then
  77.             LstSection.Items.Add('PageHeader = ' + IntToStr(Temp))   {add it to the listbox}
  78.          else
  79.             ShowMessage(GetError(JobNumber)); {show any error messages}
  80.  
  81.          {get the number of groups in the report}
  82.          NumGroups := PEGetNGroups(JobNumber);
  83.          If NumGroups > 0 then   {are there any groups}
  84.             begin
  85.                For Iterator := 0 to NumGroups - 1 do
  86.                   begin
  87.                      {get the section height for each of the Groups and add it to the list}
  88.                      if PEGetSectionHeight(JobNumber, PE_GROUPHEADER + Iterator, Temp) then
  89.                         LstSection.Items.Add('GroupHeader #' + IntToStr(Iterator + 1) + ' = ' + IntToStr(Temp))
  90.                      else
  91.                         ShowMessage(GetError(JobNumber)); {show any error messages}
  92.                   end;
  93.             end;
  94.  
  95.          {get the minimum section height for the detail section}
  96.          If PEGetSectionHeight(JobNumber, PE_DETAILSECTION, Temp) then
  97.             LstSection.Items.Add('Detail = ' + IntToStr(Temp))
  98.          else
  99.             ShowMessage(GetError(JobNumber)); {show any error messages}
  100.  
  101.          If NumGroups > 0 then  {was there more than one group}
  102.             begin
  103.                For Iterator := NumGroups - 1 downto 0 do
  104.                   begin
  105.                      {get the minimum section heights for the group footers and add them to the list}
  106.                      if PEGetSectionHeight(JobNumber, PE_GROUPFOOTER + Iterator, Temp) then
  107.                         LstSection.Items.Add('GroupFooter #' + IntToStr(Iterator + 1) + ' = ' + IntToStr(Temp))
  108.                      else
  109.                         ShowMessage(GetError(JobNumber)); {show any error messages}
  110.                   end;
  111.             end;
  112.  
  113.          {get the section height for the grand total section of the report}
  114.          If PEGetSectionHeight(JobNumber, PE_GRANDTOTALSECTION, Temp) then
  115.             LstSection.Items.Add('GrandTotal = ' + IntToStr(Temp))
  116.          else
  117.             ShowMessage(GetError(JobNumber)); {show any error messages}
  118.  
  119.          {get the section hieght for the page footer of the report}
  120.          If PEGetSectionHeight(JobNumber, PE_FOOTERSECTION, Temp) then
  121.             LstSection.Items.Add('PageFooter = ' + IntToStr(Temp))
  122.          else
  123.             ShowMessage(GetError(JobNumber)); {show any error messages}
  124.       end
  125.    else  {if the set minimum menu option is chosen}
  126.       {place the various options in the combo box}
  127.       begin
  128.          {setup for the form}
  129.          CmbSection.Visible := True;
  130.          BtnSetHeight.Visible := True;
  131.          EdtSectHeight.Visible := True;
  132.  
  133.          CmbSection.Items.Add('PageHeader');  {add the page header to the dropdown list}
  134.          Sections[SecIndex] := PE_HEADERSECTION;  {add section code to section array}
  135.          Inc(SecIndex);
  136.  
  137.          NumGroups := PEGetNGroups(JobNumber); {get number of groups}
  138.          If NumGroups > 0 then    {are there groups}
  139.             begin
  140.                For Iterator := 0 to NumGroups - 1 do
  141.                    begin
  142.                       {add the group header to the dropdown list}
  143.                       CmbSection.Items.Add('GroupHeader #' + IntToStr(Iterator + 1));
  144.                       {add section code to section array}
  145.                       Sections[SecIndex] := PE_GROUPHEADER + Iterator;
  146.                       Inc(SecIndex);
  147.                    end;
  148.             end;
  149.  
  150.          CmbSection.Items.Add('Detail');  {add the detail section to the dropdown list}
  151.          Sections[SecIndex] := PE_DETAILSECTION;  {add section code to section array}
  152.          Inc(SecIndex);
  153.  
  154.          If NumGroups > 0 then   {were there any groups}
  155.             begin
  156.                For Iterator := NumGroups - 1 downto 0  do
  157.                   begin
  158.                      {add the group footer to the dropdown list}
  159.                      CmbSection.Items.Add('GroupFooter #' + IntToStr(Iterator + 1));
  160.                      Sections[SecIndex] := PE_GROUPFOOTER + Iterator;  {add section code to section array}
  161.                      Inc(SecIndex);
  162.                   end;
  163.                end;
  164.  
  165.          {add the grant total section to the dropdown list}
  166.          CmbSection.Items.Add('GrandTotal');
  167.          Sections[SecIndex] := PE_GRANDTOTALSECTION;  {add section code to section array}
  168.          Inc(SecIndex);
  169.  
  170.          {add the page footer to the dropdown list}
  171.          CmbSection.Items.Add('PageFooter');
  172.          Sections[SecIndex] := PE_FOOTERSECTION; {add section code to section array}
  173.          CmbSection.ItemIndex := 0;
  174.       end
  175. end;
  176.  
  177. procedure TFrmSection.BtnOKClick(Sender: TObject);
  178. begin
  179.    {clean up}
  180.    LstSection.Clear;
  181.    LstSection.Visible := False;
  182.    CmbSection.Clear;
  183.    CmbSection.Visible := False;
  184.    SenderIsGet := False;
  185.    BtnSetHeight.Visible := False;
  186.    EdtSectHeight.Visible := False;
  187.    EdtSectHeight.Clear;
  188.  
  189. end;
  190.  
  191. procedure TFrmSection.FormCreate(Sender: TObject);
  192. begin
  193.    SecIndex := 0;  {initialize the array index}
  194. end;
  195.  
  196. procedure TFrmSection.CmbSectionChange(Sender: TObject);
  197. var
  198.    Temp : SmallInt;
  199.  
  200. begin
  201.    {get the minimum section height for the selected item}
  202.    if PEGetSectionHeight(JobNumber, Sections[CmbSection.ItemIndex], Temp) then
  203.       EdtSectHeight.Text := IntToStr(Temp)
  204.    else
  205.       ShowMessage(GetError(JobNumber)); {show any error messages}
  206. end;
  207.  
  208. procedure TFrmSection.BtnSetHeightClick(Sender: TObject);
  209. Var
  210.    I, Code : Integer;
  211.  
  212. begin
  213.   { Get text from TEdit control }
  214.   Val(EdtSectHeight.Text, I, Code);
  215.   { Error during conversion to integer? }
  216.   if code <> 0 then
  217.      begin
  218.         EdtSectHeight.Clear;
  219.         EdtSectHeight.SetFocus;
  220.      end
  221.   else
  222.     if PESetSectionHeight(JobNumber, Sections[CmbSection.ItemIndex], StrToInt(EdtSectHeight.Text)) = False then
  223.        ShowMessage(GetError(JobNumber)); {show any error messages}
  224. end;
  225.  
  226. end.
  227.